package com.llxz.blog.ucenter.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.llxz.blog.ucenter.entity.Relation;
import com.llxz.blog.ucenter.entity.User;
import com.llxz.blog.ucenter.mapper.RelationMapper;
import com.llxz.blog.ucenter.service.RelationService;
import com.llxz.blog.ucenter.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @author lyq
 * @description: 关系表服务实现类
 * date: 2021/9/4 15:19
 */

@Service
public class RelationServiceImpl extends ServiceImpl<RelationMapper, Relation> implements RelationService {
    @Autowired
    RelationService relationService;

    @Autowired
    UserService userService;

    @Override
    public List<User> findAll(String id) {
        QueryWrapper<Relation> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",id);

        List<Relation> list = relationService.list(wrapper);

        List<User> res = new ArrayList<>();

        for (int i = 0; i < list.size(); i++){
            res.add(userService.getById(list.get(i).getFriendId()));
        }
        return res;
    }
}
